package com.zxp.server.controller;


import com.zxp.server.config.Result;
import com.zxp.server.service.IBlogTagService;
import com.zxp.server.vo.BlogTag;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 朱小皮
 * @since 2022-05-14
 */
@Api(value = "标签管理", tags = "标签管理")
@RestController
@RequestMapping("/blogTag")
public class BlogTagController {

    @Autowired
    private IBlogTagService blogTagService;

    @ApiOperation(value = "根据博客类型获取标签")
    @GetMapping("/getTypeTags/{typeId}")
    public Result getTagsByTypeId(@PathVariable("typeId")int typeId){
        HashMap<String, Object> param = new HashMap<>();
        param.put("typeid",typeId);
        List<BlogTag> BlogTag = blogTagService.getBaseMapper().selectByMap(param);
        return Result.success("获取标签列表成功",BlogTag);
    }


    @ApiOperation(value = "新增标签")
    @PostMapping("/addTag")
    public Result addTag(@RequestBody BlogTag blogTag){
        blogTagService.getBaseMapper().insert(blogTag);
        return Result.success("添加成功");
    }

    @ApiOperation(value = "获取所有标签")
    @GetMapping("/allTag")
    public Result getAllTag(){
        List<BlogTag> blogTags = blogTagService.getBaseMapper().selectList(null);
        return  Result.success("获取成功",blogTags);
    }


}
